module rng
#ifdef RNGMCCARD
    interface 
        function GetRN() result(ret)
        real(8) :: ret  
        !dec$attributes c, alias:'_getRN' :: GetRN
        end function 
    end interface
#endif
#ifdef RNGMCNP
contains
function GetRN() result(ret)
    use mcnp_random
    real(8) :: ret  
    ret = rang()
end function 
subroutine initRN()
    use mcnp_params
    use mcnp_random
    implicit real(dknd) (a-h,o-z)
    integer(i8knd)    :: i8_seed

    i8_seed = 5_i8knd**19+1
    call RN_init_problem( new_standard_gen = 1, new_seed = i8_seed, output = .false.)
end subroutine
#endif
#ifndef RNGMCCARD
#ifndef RNGMCNP
    integer, private, save :: ix1, ix2
contains
subroutine initRN(seedindex)
    integer, intent(in) :: seedindex
    ix1=seedindex*2**32+386103
    ix2=seedindex*2**16+192305
end subroutine

function GetRN() result(ret)
    use ifport
    real(8) :: ret  
!    K=IX1/53668
!    IX1=40014*(IX1-K*53668)-K*12211
!    IF (IX1.LT.0.0) IX1=IX1+2147483563
!    K=IX2/53668
!    IX2=40692*(IX2-K*52774)-K*3791
!    IF (IX2.LT.0.0) IX2=IX2+2147483399
!    IZ=IX1-IX2
!    IF (IZ.LT.1) IZ=IZ+2147483562
!    ret=FLOAT(IZ)*4.656613E-10_8
!    
!    if (ret<0 .or. ret>1.0_8) then
!        print *, "ERROR", ret
!    endif
    ret = drand(0)

end function 
#endif
#endif

end module
